package com.testcase;

import com.util.Caculator;
import io.qameta.allure.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.function.Executable;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;


@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@Epic("计算器加法和除法项目")
@Feature("冒烟测试")
public class EvnTestAssertAll {
    @Order(1)
    @Test
    @Story("加法测试")
    @DisplayName("加法")
    public void addTest() throws InterruptedException {
        int result= Caculator.add(4,2);
        System.out.println("加法计算结果： "+result);
        int result1= Caculator.add(4,-2);
        System.out.println("加法计算结果： "+result1);
//        int result2= Caculator.add(4,2);
//        System.out.println("加法计算结果： "+result2);
        int result3= Caculator.add(0,100);
        System.out.println("加法计算结果： "+result3);

        assertAll("加法结果校验",
                ()->assertEquals(6,result),
                ()->assertEquals(2,result1),
//                ()->assertEquals(2,result2),
                ()->assertEquals(100,result3)
        );
    }

    @Order(3)
    @Test
    @DisplayName("循环加法")
    public void addTest01() throws InterruptedException {
        ArrayList<Executable> assertList= new ArrayList<>();
        for(int i=0;i<10;i++){
            int result= Caculator.add(1,i);
            System.out.println("加法计算结果"+ result);
            assertList.add(() ->assertEquals(5,result));
        }
        assertAll("加法结果校验",assertList.stream());
    }

    @Order(2)
    @Test
    @Story("除法测试")
    @DisplayName("除法")
    public void divTest() throws InterruptedException {
        int result= Caculator.div(4,2);
        System.out.println("除法计算结果： "+result);
        int result1= Caculator.div(4,-2);
        System.out.println("除法计算结果： "+result1);
        int result3= Caculator.div(100,1);
        System.out.println("除法计算结果： "+result3);
        int result4= Caculator.div(0,100);
        System.out.println("除法计算结果： "+result4);


        try{
            int result5= Caculator.div(1,0);
            System.out.println("除法计算结果： "+result5);
            Allure.addAttachment("脚本名称", "除法测试用例！");
            }catch (ArithmeticException e){
            e.printStackTrace();
            System.out.println("不能除0");
            Allure.addAttachment("1","image/jpg",this.getClass().getResourceAsStream("/1.jpg"),".jpg");
        }

            assertAll("除法结果校验",
                    ()->assertEquals(2,result),
                    ()->assertEquals(-2,result1),
                    ()->assertEquals(100,result3),
                    ()->assertEquals(0,result4)
            );

        }
        @Attachment(value = "Page screenshot", type = "image/png")
        public byte[] saveScreenshot(byte[] screenShot) {
        return screenShot; }

    }

